package com.itbour.web.action.goods;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;

import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.ServletActionContext;

import com.itbour.common.base.BaseAction;
import com.itbour.def.Constants;
import com.itbour.def.SystemConf;
import com.itbour.dto.com.UserInfoDto;
import com.itbour.dto.goods.GoodsInfoDto;
import com.itbour.dto.goods.ResourceTypeInfoDto;
import com.itbour.helper.CommonHelper;
import com.itbour.service.goods.GoodsService;
import com.opensymphony.xwork2.ActionContext;


/**
 * copyright pirate alliance team 2014
 *
 * @author lw
 */

public class GoodsManagerWebAction extends BaseAction {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private GoodsService goodsService;

	private List<GoodsInfoDto> goodsList;
	
	/**日本語商品詳細＊＊*/
	//商品名
	private String goodsName1;
	//価額
	private String goodsPrice1;
	//説明
	private String description1;
	//状態
	private String status1="1";
	
    private File file1;

    private String file1ContentType;

    private String file1FileName;
    private String file1FileUrl;
	
	/**簡体中文商品詳細＊＊*/
	//商品名
	private String goodsName2;
	//価額
	private String goodsPrice2;
	//説明
	private String description2;
	//状態
	private String status2 ="1" ;
	
    private File file2;

    private String file2ContentType;

    private String file2FileName;
    private String file2FileUrl;
    
    
	/**English商品詳細＊＊*/
	//商品名
	private String goodsName3;
	//価額
	private String goodsPrice3;
	//説明
	private String description3;
	//状態
	private String status3 = "1";
	
    private File file3;

    private String file3ContentType;

    private String file3FileName;
    private String file3FileUrl;
    
	private List<ResourceTypeInfoDto> resourceList;
    
    private String selectedAreaID;
    
	/**goodsIdForModify＊＊*/
	private String goodsIdForModify="";
	private String languageIdForModify="";
	
	private String selectedResourceTypes;
	
	private Map<String, String> payTypeMap;
	
	private int pay_type_id;
	
	private String addGoodsFlag;
	
	private String selectLanguageFlag;
	//add by hmh
	private String mapFlag;
	
	public String getMapFlag() {
		return mapFlag;
	}

	public void setMapFlag(String mapFlag) {
		this.mapFlag = mapFlag;
	}


	
	private void saveFile(File file,String fileContentType, String fileName, String langName,String goodsId) throws IOException{
		
       if(file==null)
        {
    	   return ;
        }
		
		// 以服务器的文件保存地址和原文件名建立上传文件输出流
		//String  rootPath = ServletActionContext.getServletContext().getRealPath("/images/goodsPhotos/");
       String  rootPath = SystemConf.getImageRootDir() + Constants.PATH_SEPEARTOR + Constants.GOODS_IMAGE_PATH + Constants.PATH_SEPEARTOR;
		File savePath = new File(rootPath+Constants.PATH_SEPEARTOR+ goodsId+Constants.PATH_SEPEARTOR+langName);
		if(!savePath.exists()){
			savePath.mkdirs();
		}
		
	  //String path = ServletActionContext.getServletContext().getRealPath("/images/goodsPhotos/"+goodsId+"/"+langName);
		String path = SystemConf.getImageRootDir()+Constants.PATH_SEPEARTOR + Constants.GOODS_IMAGE_PATH + Constants.PATH_SEPEARTOR+goodsId+Constants.PATH_SEPEARTOR+langName;
        InputStream is=new FileInputStream(file);

        OutputStream os=new FileOutputStream(new File(path,fileName));

        byte[] buf=new byte[1024];

        int length=0;

        while((length=is.read(buf))>0)

        {
            os.write(buf, 0, length);
        }
        is.close();
        os.close();
         
	}
	
	public String getFile1FileUrl() {
		return file1FileUrl;
	}

	public void setFile1FileUrl(String file1FileUrl) {
		this.file1FileUrl = file1FileUrl;
	}

	public String getFile2FileUrl() {
		return file2FileUrl;
	}

	public void setFile2FileUrl(String file2FileUrl) {
		this.file2FileUrl = file2FileUrl;
	}

	public String getFile3FileUrl() {
		return file3FileUrl;
	}

	public void setFile3FileUrl(String file3FileUrl) {
		this.file3FileUrl = file3FileUrl;
	}

	//更新商品
	public String updateGoods()
	{
		
		return SUCCESS;
	}

	/**
	 * @return the goodsService
	 */
	public GoodsService getGoodsService() {
		return goodsService;
	}

	/**
	 * @param goodsService the goodsService to set
	 */
	public void setGoodsService(GoodsService goodsService) {
		this.goodsService = goodsService;
	}

	public List<GoodsInfoDto> getGoodsList() {
		return goodsList;
	}

	public void setGoodsList(List<GoodsInfoDto> goodsList) {
		this.goodsList = goodsList;
	}

	public String getGoodsName1() {
		return goodsName1;
	}

	public void setGoodsName1(String goodsName1) {
		this.goodsName1 = goodsName1;
	}

	public String getGoodsPrice1() {
		return goodsPrice1;
	}

	public void setGoodsPrice1(String goodsPrice1) {
		this.goodsPrice1 = goodsPrice1;
	}

	public String getDescription1() {
		return description1;
	}

	public void setDescription1(String description1) {
		this.description1 = description1;
	}

	public String getStatus1() {
		return status1;
	}

	public void setStatus1(String status1) {
		this.status1 = status1;
	}

	public String getGoodsName2() {
		return goodsName2;
	}

	public void setGoodsName2(String goodsName2) {
		this.goodsName2 = goodsName2;
	}

	public String getGoodsPrice2() {
		return goodsPrice2;
	}

	public void setGoodsPrice2(String goodsPrice2) {
		this.goodsPrice2 = goodsPrice2;
	}

	public String getDescription2() {
		return description2;
	}

	public void setDescription2(String description2) {
		this.description2 = description2;
	}

	public String getStatus2() {
		return status2;
	}

	public void setStatus2(String status2) {
		this.status2 = status2;
	}

	public String getGoodsName3() {
		return goodsName3;
	}

	public void setGoodsName3(String goodsName3) {
		this.goodsName3 = goodsName3;
	}

	public String getGoodsPrice3() {
		return goodsPrice3;
	}

	public void setGoodsPrice3(String goodsPrice3) {
		this.goodsPrice3 = goodsPrice3;
	}

	public String getDescription3() {
		return description3;
	}

	public void setDescription3(String description3) {
		this.description3 = description3;
	}

	public String getStatus3() {
		return status3;
	}

	public void setStatus3(String status3) {
		this.status3 = status3;
	}

	public String getGoodsIdForModify() {
		return goodsIdForModify;
	}

	public void setGoodsIdForModify(String goodsIdForModify) {
		this.goodsIdForModify = goodsIdForModify;
	}

	public File getFile1() {
		return file1;
	}

	public void setFile1(File file1) {
		this.file1 = file1;
	}

	public File getFile2() {
		return file2;
	}
	
	public void setFile2(File file2) {
		this.file2 = file2;
	}

	public File getFile3() {
		return file3;
	}

	public void setFile3(File file3) {
		this.file3 = file3;
	}

	public String getFile1ContentType() {
		return file1ContentType;
	}

	public void setFile1ContentType(String file1ContentType) {
		this.file1ContentType = file1ContentType;
	}

	public String getFile1FileName() {
		return file1FileName;
	}

	public void setFile1FileName(String file1FileName) {
		this.file1FileName = file1FileName;
	}

	public String getFile2ContentType() {
		return file2ContentType;
	}

	public void setFile2ContentType(String file2ContentType) {
		this.file2ContentType = file2ContentType;
	}

	public String getFile2FileName() {
		return file2FileName;
	}

	public void setFile2FileName(String file2FileName) {
		this.file2FileName = file2FileName;
	}

	public String getFile3ContentType() {
		return file3ContentType;
	}

	public void setFile3ContentType(String file3ContentType) {
		this.file3ContentType = file3ContentType;
	}

	public String getFile3FileName() {
		return file3FileName;
	}

	public void setFile3FileName(String file3FileName) {
		this.file3FileName = file3FileName;
	}

	public String getLanguageIdForModify() {
		return languageIdForModify;
	}

	public void setLanguageIdForModify(String languageIdForModify) {
		this.languageIdForModify = languageIdForModify;
	}

	public String getSelectedAreaID() {
		return selectedAreaID;
	}

	public void setSelectedAreaID(String selectedAreaID) {
		this.selectedAreaID = selectedAreaID;
	}

	public List<ResourceTypeInfoDto> getResourceList() {
		return resourceList;
	}

	public void setResourceList(List<ResourceTypeInfoDto> resourceList) {
		this.resourceList = resourceList;
	}

	public String getSelectedResourceTypes() {
		return selectedResourceTypes;
	}

	public void setSelectedResourceTypes(String selectedResourceTypes) {
		this.selectedResourceTypes = selectedResourceTypes;
	}

	public Map<String, String> getPayTypeMap() {
		return payTypeMap;
	}

	public void setPayTypeMap(Map<String, String> payTypeMap) {
		this.payTypeMap = payTypeMap;
	}

	public int getPay_type_id() {
		return pay_type_id;
	}

	public void setPay_type_id(int pay_type_id) {
		this.pay_type_id = pay_type_id;
	}
	
	public String getAddGoodsFlag() {
		return addGoodsFlag;
	}

	public void setAddGoodsFlag(String addGoodsFlag) {
		this.addGoodsFlag = addGoodsFlag;
	}

	public String getSelectLanguageFlag() {
		return selectLanguageFlag;
	}

	public void setSelectLanguageFlag(String selectLanguageFlag) {
		this.selectLanguageFlag = selectLanguageFlag;
	}
}
